2026-05-28 Using the units command to convert celsius to fahrenheit on FreeBSD
At some point I had a sensor collecting temperature measurements and the format came out something like this.
Temperature: 29.86 °C
Nothing fancy however being non-fluent in Celsius-Fahrenheit conversions quite often when it came to conversions I tended to do the following:
Use search engine with search terms `convert celsius to fahrenheit`
Find a suitable candidate in the list of results and hope it isn't ad-laden drivel
Fire up a web browser if I had forgotten to start one or open a new tab
Go back to the terminal I was working in and copy the temperature
Paste it back into the browser tab after cursing I lost mouse focus
Finally get the results and pray that the webpage didn't have javascript preventing something as trivial as copying the calculation result
I had forgotten after some time that there are probably CLI tools for this but that got into another type of yak shave. But then I remembered reading (and forgetting) that FreeBSD includes in the base system something called units. It's built exactly for this purpose. A small excerpt from the manpage shows its history.
HISTORY
The units first appeared in NetBSD and was ported to FreeBSD 2.2.0.
Alright, let's try this out! Let's be cavalier and fire up the utility and use it...
$ units
751 units, 62 prefixes
You have: ?
unknown unit '?'
You have: help
unknown unit 'help'
Okay, I realized I have never used this tool at all so I have asked uninformed dumb things and got (dumb) answers. To be slightly fair to myself it's not listed in Wikipedia's list of POSIX commands.
Alright, let's try reading the docs since unlike in penguin-land manpages for base system commands are part of the batteries included.
$ man units
...
...
...
And we find out that the following:
FILES
/usr/share/misc/definitions.units The standard units file.
Excellent, well let's ask the handy file utility to do a base identification of what's inside.
$ file /usr/share/misc/definitions.units
/usr/share/misc/definitions.units: ASCII text
Nice, it's an ascii file. Alright, let's take a peak.
$ head /usr/share/misc/definitions.units
# primitive units
m !a!
kg !b!
sec !c!
coul !d!
candela !e!
usdollar !f!
euro !g!
Okay, simple structured tabular-ish data. Let's grep around.
$ grep degrees /usr/share/misc/definitions.units
degreesrankine 5|9 K
degrankine degreesrankine
degreerankine degreesrankine
degreesrankine sounds like another trip to Wikipedia (not in this post) and other such search engine journeys.
Let's widen the grep a little. Sometimes being more vague gets you more
$ grep deg /usr/share/misc/definitions.units
degree 1|180 pi-radian
grade .9 degree
arcdeg 1 degree
arcmin 1|60 arcdeg
k 1.38047e-16 erg/degC
degC 1&+273.15 K
degF 5|9&255.37222222222222222222 K
degreesrankine 5|9 K
degrankine degreesrankine
degreerankine degreesrankine
degreaumur 10|8&+273.15 K
gasmark 25|1&250 degF
Stufe 25|1&125 degC
Okay, I think we have something here...
Let's try this again
$ units
You have: degC
You want: degF
(-> x*1.8g 32g)
(<- y*0.55555556g -17.777778g)
Whoops, need a number. Let's try again...
$ units
You have: 28.91
You want: degF
conformability error
28.91
0.55555556&255.37222 K
The program expects the temperature and the unit together on one line. And below is the working example:
$ units
You have: 28.91 degC
You want: degF
84.038
I illustrated a lot of the typos and mistakes I did on my journey to calculate Celsius to Fahrenheit in order to hopefully illustrate things a little more. This process took me perhaps a few seconds or so.
Sometimes it's good to spell out in detail what is happening in that amount of time for others who are less cli fluent. It's a little late to learn UNIX when big iron UNIX computed the planet, unfortunately.
Note, a far more typical flow is to:
Find the name of base utility in FreeBSD
Read the manpage
Find the examples in the manpage
Adapt to your situation
Sometimes the answers to your problems are already there, you just need the instructions to unlock it.